package com.hongye.manager.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hongye.common.entity.OrderEntity;
import com.hongye.common.response.ResponseResult;
import com.hongye.manager.mapper.OrderMapper;
import com.hongye.manager.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private OrderService service;

    @RequestMapping("/list")
    public ResponseResult list(){
        List<OrderEntity> list = orderMapper.selectList(null);
        HashMap<String, Object> map = new HashMap<>();
        map.put("list",list);
        return ResponseResult.ok(1,"成功",map);
    }

    @RequestMapping("/del")
    public ResponseResult del(Integer id){
        int i = orderMapper.deleteById(id);
        HashMap<String, Object> map = new HashMap<>();
        map.put("i",i);
        return ResponseResult.ok(1,"成功",map);
    }

    @RequestMapping("findlist")
    public List<OrderEntity> findlist(String name,String phone){
        QueryWrapper<OrderEntity> wrapper = new QueryWrapper<>();
        wrapper.like("customer_name",name);
        wrapper.eq("phone",phone);
        List<OrderEntity> findlist = orderMapper.selectList(wrapper);
        return findlist;
    }

    @RequestMapping("/findPage")
    public List<OrderEntity> fenye(@RequestParam(value = "page",defaultValue = "1") int page, @RequestParam(value = "size",defaultValue = "10") int size, @RequestParam String name){
        //创建分页对象
        Page<OrderEntity> paged = new Page<>(page,size);
        List<OrderEntity> jobInfos = service.selectUserPage(paged,name);
        return jobInfos;
    }
}

